﻿@model BskLeague.Models.Communicate

@{
    ViewBag.Title = "Nowy komunikat";
}

<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<script src="../../Scripts/jquery-ui-1.8.11.min.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.unobtrusive-ajax.min.js" type="text/javascript"></script>
<script src="../../Scripts/jquery-1.5.1.min.js" type="text/javascript"></script>
<script type="text/javascript">

    function DetailsDropDownChange() {
        var value = $("#DetailsDropDown").val();
        $("#RL").val(value);
        $("#Recievers").text(value);
    }

    $(document).ready(function () {
        $("#Details").hide();
        $("#DetailsDropDown").change(function () {
            DetailsDropDownChange();
        });

        $("#MyTeam").click(function () {
            //alert("myteam");
            $("#Details").hide();
            $.post("/MyPlayer/GetTeam", {},
                    function (data) {
                        var players = [];
                        var users = [];
                        var direction = true;
                        $.each(data, function (key, val) {
                            if (direction) {
                                players.push(val);
                                direction = false;
                            }
                            else {
                                users.push(val);
                                direction = true;
                            }
                        });

                        $("#RL").val("");
                        $(users).each(function () {
                            var str = $("#RL").val();
                            str += this + ";";
                            $("#RL").val(str);
                        });
                        var str = $("#RL").val();
                        str = str.substring(0, str.length - 1);
                        $("#RL").val(str);
                        $("#Recievers").text(str);

                    }); //koniec post

        }); //koniec myteam click

        $("#MyPlayer").click(function () {
            $("#DetailsDropDown").empty();
           // alert("MyPlayer");
            $.post("/MyPlayer/GetTeam", {},
                    function (data) {
                        //alert("ajax baby");
                        var players = [];
                        var users = [];
                        var direction = true;
                        $.each(data, function (key, val) {
                            if (direction) {
                                players.push(val);
                                direction = false;
                            }
                            else {
                                users.push(val);
                                direction = true;
                            }
                        });

                        for (var i = 0; i < players.length; i++) {
                            $("#DetailsDropDown").append("<option value=\"" + users[i].toString() + "\">" + players[i].toString() + "</option>");
                        }
                        $("#Details").show();
                        DetailsDropDownChange();
                    }); //koniec post

        }); //koniec MyPlayer click

    });                       //koniec document ready




</script>

@Html.Partial("_Submenu", (BskLeague.Models.Player) ViewBag.player)

@using (Html.BeginForm())
{
    @Html.ValidationSummary(true)

        <h3>Nowy komunikat</h3>
        <div>
            Do kogo chcesz wysłać komunikat: <br>
            <a href="#" id="MyTeam">Wszyscy zawodnicy z mojej drużyny</a> |
            <a href="#" id="MyPlayer">Gracz mojej drużyny</a>
        </div>
        <div id="Details">
            Wybierz:
            <select id="DetailsDropDown">
            </select>
        </div>
        <div>
            Adresaci:
        <div id="Recievers">
                 
            </div>
        </div>

        <input id="RL" type="hidden" name="RL" value="ala" />

        <div class="editor-label">
            @Html.LabelFor(model => model.Content)
        </div>
        <div class="editor-field">
            @Html.TextAreaFor(model => model.Content, 5, 40, null)
            @Html.ValidationMessageFor(model => model.Content)
        </div>
        <p>
            <input type="submit" value="Wyślij" />
        </p>

}

<div>
    @Html.ActionLink("Powrót do komunikatów", "Communicates")
</div>

